﻿package com.ld.hpfs.service.impl;

import com.google.common.base.Function;
import com.ld.hpfs.common.utils.DoubleUtil;
import com.ld.hpfs.dao.DealMapper;
import com.ld.hpfs.service.DealService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.CallableStatementCallback;
import org.springframework.jdbc.core.CallableStatementCreator;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import static com.google.common.collect.Lists.newArrayList;
import static com.ld.hpfs.utils.BatchProcessHelper.batchProcess;

@Service
public class DealServiceImpl implements DealService {

    private static final Logger logger = LoggerFactory.getLogger(DealServiceImpl.class);

    @Autowired
    private DealMapper dealMapper;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void updateStateFlag(HashMap<String, Object> param) {

        dealMapper.updateStateFlag(param);

    }

    @Override
    public ArrayList<HashMap<String, Object>> getDealSearchList(HashMap<String, Object> param) {
        int count = dealMapper.getDealSearchListCount(param);
        if (count == 0) {
            return null;
        } else {
            param.put("pageCount", count);
            return dealMapper.getDealSearchList(param);
        }
    }

    @Override
    public ArrayList<HashMap<String, Object>> getDealPrintList(HashMap<String, Object> param) {
        int count = dealMapper.getDealPrintListCount(param);
        if (count == 0) {
            return null;
        } else {
            param.put("pageCount", count);
            return dealMapper.getDealPrintList(param);
        }
    }

    @Override
    public ArrayList<HashMap<String, Object>> getDealFieldList(HashMap<String, Object> param) {
        if (param.get("lang").equals("en")) {
            return dealMapper.getDealFieldList1();
        } else {
            return dealMapper.getDealFieldList();
        }

    }

    @Override
    public String getInitOrderStr(HashMap<String, Object> param) {
        try {
            ArrayList<HashMap<String, Object>> orders = dealMapper.getInitOrderStr(param);
            StringBuilder str = new StringBuilder();
            if (orders.size() > 0) {//拼写排序(orderby)sql
                for (int i = 0; i < orders.size() - 1; i++) {
                    String property = orders.get(i).get("field_name").toString();//,is_asc
                    String dir = orders.get(i).get("is_asc").toString().equals("1") ? "asc" : "desc";
                    str.append(property + " " + dir + ",");
                }
                String lastPro = orders.get(orders.size() - 1).get("field_name").toString();
                String lastdir = orders.get(orders.size() - 1).get("is_asc").toString().equals("1") ? "asc" : "desc";
                str.append(lastPro + " " + lastdir);
            }
            return str.toString();
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return "";
        }
    }

    @Override
    public int savePrintOrder(HashMap<String, Object> param) {
        try {
            ArrayList<HashMap<String, Object>> check = dealMapper.getInitOrderStr(param);
            if (!check.isEmpty()) {
                dealMapper.deletePrintOrder(param);
            }
            ArrayList<HashMap<String, Object>> list = (ArrayList<HashMap<String, Object>>) param.get("list");
            if (!list.isEmpty()) {
                dealMapper.insertPrintOrder(param);
            }
            return 0;
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return -1;
        }
    }

    @Override
    public ArrayList<HashMap<String, Object>> getPrintOrder(HashMap<String, Object> param) {
        ArrayList<HashMap<String, Object>> orders = dealMapper.getInitOrderStr(param);
        return orders;
    }

    @Override
    public ArrayList<HashMap<String, Object>> getDealPrintForExport(final HashMap<String, Object> param) {
        List<HashMap<String, Object>> head = batchProcess(param, queryHeadInfoForExport());
        batchProcess(param, updateStateToPrinted());

        logger.debug("{}", "-----------------------");
        logger.debug("{}", head);
        ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
        String outCode = "";//定义outcode字符串
        if (!head.isEmpty()) {
            //TODO: this piece of code will cause performance issue, need refactor --add by PENG Hongwei
            for (HashMap<String, Object> aHead : head) {
                String DOCUMENT_NO = aHead.get("DOCUMENT_NO").toString();
                String headId = aHead.get("ID_HEAD_ID").toString();
                Integer temp = dealMapper.getGen_OutCode(param);//获得是否生成outcode字段的标志位  0：表示不生成  1：表示生成
                HashMap<String, Object> detailParam = new HashMap<String, Object>();
                detailParam.put("DOCUMENT_NO", DOCUMENT_NO);
                detailParam.put("companyId", param.get("companyId"));
                ArrayList<HashMap<String, Object>> details = dealMapper.getDetailInfoForExport(detailParam);
                if (temp == 1 || temp == null) {//如果是1表示需要生成outcode
                    outCode = getOutCode();//获得函数方法的outcode字符串
                }

                aHead.put("details", details);
                aHead.put("count", details.size());
                aHead.put("outCode", outCode);

                HashMap<String, Object> map = new HashMap<String, Object>();
                map.put("headId", headId);
                map.put("outCode", outCode);
                list.add(map);

            }
        }
        logger.debug("{}", "-----------------------");
        logger.debug("{}", list);
        logger.debug("{}", "-----------------------");
         /*根据获得的headid和outcode字段更新数据库*/
        dealMapper.updateOutCodeByOutCode(list);

        return newArrayList(head);
    }

    private Function<HashMap<String, Object>, List<HashMap<String, Object>>> updateStateToPrinted() {
        return new Function<HashMap<String, Object>, List<HashMap<String, Object>>>() {
            @Override
            public List<HashMap<String, Object>> apply(HashMap<String, Object> param) {
                dealMapper.UpdateStateToPrinting(param);//更新状态为“已导出”
                return null;
            }
        };
    }

    private Function<HashMap<String, Object>, List<HashMap<String, Object>>> queryHeadInfoForExport() {
        return new Function<HashMap<String, Object>, List<HashMap<String, Object>>>() {
            @Override
            public List<HashMap<String, Object>> apply(HashMap<String, Object> param) {
                return dealMapper.getHeadInfoForExport(param);
            }
        };
    }

    public String getOutCode() {
        String param2Value = (String) jdbcTemplate.execute(
                new CallableStatementCreator() {
                    @Override
                    public CallableStatement createCallableStatement(Connection con) throws SQLException {
                        String storedProc = "{call sp_tax_get_outcode(?)}";// 调用的sql
                        CallableStatement cs = con.prepareCall(storedProc);
                        cs.registerOutParameter(1, Types.VARCHAR);// 注册输出参数的类型

                        return cs;
                    }
                }, new CallableStatementCallback() {
                    @Override
                    public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
                        cs.execute();
                        return cs.getString(1);// 获取输出参数的值
                    }
                }
        );
        //	result = enterInvoiceMapper.getVoucherOperater(company_id);

        return param2Value;


    }

    @Override
    public int setDeInvoiced(HashMap<String, Object> param) {
        try {
            dealMapper.setDeInvoiced(param);
            return 0;
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return -1;
        }
    }

    @Override
    public int setInvoiced(HashMap<String, Object> param) {
        try {
            dealMapper.setInvoiced(param);
            return 0;
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return -1;
        }
    }

    @Override
    public int setKeep(HashMap<String, Object> param) {
        try {
            dealMapper.setKeep(param);
            return 0;
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return -1;
        }
    }

    @Override
    public int setDeKeep(HashMap<String, Object> param) {
        try {
            dealMapper.setDeKeep(param);
            return 0;
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return -1;
        }
    }

    //查询处理--删除
    @Override
    public int dealSearchDelete(HashMap<String, Object> param) {
        int result = -1;
        Connection conn = null;
        String companyId = (String) param.get("company_id");
        String ids = (String) param.get("ids");
        try {

            CallableStatement proc = null;
            conn = jdbcTemplate.getDataSource().getConnection();
            proc = conn.prepareCall("{ call sp_tax_del_invoice(?,?) }");
            proc.setString(1, ids);
            proc.setInt(2, Integer.parseInt(companyId));
            proc.execute();
            result = 0;
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (Exception ex) {
            logger.error(ex.getMessage());
        } finally {
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }

    //取消审核
    @Override
    public int cancelAudit(HashMap<String, Object> param) {
        try {

            List<HashMap<String, Object>> List = (List<HashMap<String, Object>>) param.get("list");
            if (List != null && List.size() > 0) {
                List<HashMap<String, Object>> subList = new ArrayList<HashMap<String, Object>>();
                for (int i = 0; i < List.size(); ++i) {
                    subList.add(List.get(i));
                    if (subList.size() == 5) {
                        param.put("list", subList);
                        dealMapper.cancelAudit(param);
                        subList.clear();
                    }
                }
                if (subList.size() > 0) {
                    param.put("list", subList);
                    dealMapper.cancelAudit(param);
                }
            }
            return 0;
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return -1;
        }
    }

    @Override
    public int setAssociatPreopen(HashMap<String, Object> param) {
        try {
            dealMapper.setAssociatPreopen(param);
            return 0;
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return -1;
        }
    }

    @Override
    public int setAssociatPreclose(HashMap<String, Object> param) {
        try {
            dealMapper.setAssociatPreclose(param);
            return 0;
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return -1;
        }
    }

    @Override
    public int setAssociatPreclosere(HashMap<String, Object> param) {
        try {
            dealMapper.setAssociatPreclosere(param);
            return 0;
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return -1;
        }
    }

    @Override
    public int setToPrint(HashMap<String, Object> param) {
        try {
            List<HashMap<String, Object>> addList = (List<HashMap<String, Object>>) param.get("list");
            if (addList != null && addList.size() > 0) {
                List<HashMap<String, Object>> subAddList = new ArrayList<HashMap<String, Object>>();
                for (int i = 0; i < addList.size(); ++i) {
                    subAddList.add(addList.get(i));
                    if (subAddList.size() == 5) {
                        param.put("list", subAddList);
                        dealMapper.setToPrint(param);
                        subAddList.clear();
                    }
                }
                if (subAddList.size() > 0) {
                    param.put("list", subAddList);
                    dealMapper.setToPrint(param);
                }
            }
            return 0;
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return -1;
        }
    }


    /*该功能：
     * 1.先判断导出功能是否生成outcode,如果生成的话则根据存储过程生成，并且更新数据库的outcode字段。
     * 	  返回的结果集中单据号的那一列显示的是'outcode'字段
     * 2.如果不生成outcode，则根据param里面的数据直接找到要打印的数据信息
     * */
    @Override
    public List<HashMap<String, Object>> getExportExcelList(HashMap<String, Object> param) {
        String outCode = "";//定义outcode字符串
        List<HashMap<String, Object>> excellist;//用于返回要打印的excel结果集
        ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
        Integer temp = dealMapper.getGen_OutCode(param);//获得是否生成outcode字段的标志位  0：表示不生成  1：表示生成
        if (temp == 1 || temp == null) {//如果是1表示需要生成outcode

            List<HashMap<String, String>> listdoc = (List<HashMap<String, String>>) param.get("list");//list里面是id_head_id
            for (HashMap<String, String> ids : listdoc) {
                String headId = ids.get("id");
                HashMap<String, Object> map = new HashMap<String, Object>();

                outCode = getOutCode();//获得函数方法的outcode字符串

                map.put("headId", headId);
                map.put("outCode", outCode);
                list.add(map);
            }

            dealMapper.updateOutCodeByOutCode(list); /*根据获得的headid和outcode字段更新数据库*/
            excellist = batchProcess(param, getExportExcelList());
            for (HashMap<String, Object> info : excellist) {
                info.put("单据号/编码", info.get("OUTCODE"));
            }
        } else {
            excellist = batchProcess(param, getExportExcelList());
        }
        return excellist;
    }

    private Function<HashMap<String, Object>, List<HashMap<String, Object>>> getExportExcelList() {
        return new Function<HashMap<String, Object>, List<HashMap<String, Object>>>() {
            @Override
            public List<HashMap<String, Object>> apply(HashMap<String, Object> param) {
                return dealMapper.getExportExcelList(param);
            }
        };
    }

    @Override
    public List<HashMap<String, Object>> getSearchExportExcelList(HashMap<String, Object> param) {
        return batchProcess(param, querySearchExportExcelList());
    }

    private Function<HashMap<String, Object>, List<HashMap<String, Object>>> querySearchExportExcelList() {
        return new Function<HashMap<String, Object>, List<HashMap<String, Object>>>() {
            @Override
            public List<HashMap<String, Object>> apply(HashMap<String, Object> param) {
                return dealMapper.getSearchExportExcelList(param);
            }
        };
    }

    @Override
    public ArrayList<HashMap<String, Object>> getDocumentNO(HashMap<String, Object> param) {
        try {
            return dealMapper.getDocumentNO(param);
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return null;
        }
    }

    @Override
    public ArrayList<HashMap<String, Object>> getInvoiceNum(HashMap<String, Object> param) {
        try {
            return dealMapper.getInvoiceNum(param);
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return null;
        }
    }

    @Override
    public ArrayList<HashMap<String, Object>> getCustomList(HashMap<String, Object> param) {
        try {
            return dealMapper.getCustomList(param);
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return null;
        }
    }

    @Override
    public ArrayList<HashMap<String, Object>> getGoodsNameList(HashMap<String, Object> param) {
        try {
            return dealMapper.getGoodsNameList(param);
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return null;
        }
    }

    @Override
    public int updateInvoiceStateFromImport(HashMap<String, Object> param) {
        try {
            dealMapper.updateInvoiceStateFromImport(param);
            if (((ArrayList<HashMap<String, Object>>) param.get("list_detail")).size() > 0) {
                dealMapper.insertInvoiceStateDetailFromImport(param);
            }
            dealMapper.insertInvoiceStateFromImport(param);
            return 0;
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return -1;
        }

    }

    @Override
    public List<HashMap<String, Object>> getPrintList(
            HashMap<String, Object> param) {
        return dealMapper.getPrintList(param);
    }

    @Override
    public int setExportType(HashMap<String, Object> param) {
        return dealMapper.setExportType(param);
    }

    @Override
    public void updateDoc_Status(HashMap<String, Object> param) {
        dealMapper.updateDoc_Status(param);
    }

    @Override
    public void savePrintList(List<HashMap<String, Object>> list) {
        dealMapper.savePrintList(list);
    }

    @Override
    public void updateDoc_StatusTo1(HashMap<String, Object> param) {
        dealMapper.updateDoc_StatusTo1(param);
    }

    @Override
    public void delectDOCUMENT_NOFromTAX_NUMS(
            List<HashMap<String, Object>> lists) {
        dealMapper.delectDOCUMENT_NOFromTAX_NUMS(lists);
    }

    @Override
    public int getNumsByTax_nums() {
        return dealMapper.getNumsByTax_nums();

    }

    @Override
    public void savePrintListToTax_nums(HashMap<String, Object> param) {
        dealMapper.savePrintListToTax_nums(param);
    }

    @Override
    public HashMap<String, Object> getPrintingInfo() {
        int count = dealMapper.getPrintingCount();
        if (count == 0) {
            return dealMapper.getPrintingInfo();

        } else {
            return null;
        }
    }

    @Override
    public void setPrint_ModeToRunning(String DOCUMENT_NO) {
        dealMapper.setPrint_ModeToRunning(DOCUMENT_NO);
    }

    @Override
    public ArrayList<HashMap<String, Object>> getDetailListForSplit(HashMap<String, Object> param) {
        try {
            return dealMapper.getDetailListForSplit(param);
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return null;
        }
    }

    @Override
    public ArrayList<HashMap<String, Object>> finddealStateUnsplitUnmerge(
            HashMap<String, Object> param) {
        return dealMapper.finddealStateUnsplitUnmerge(param);
    }

    @Override
    public ArrayList<HashMap<String, Object>> existsDataByDoc_No(
            HashMap<String, Object> param) {
        return dealMapper.existsDataByDoc_No(param);
    }

    @Override
    public int ImportExcelAerMapping(HashMap<String, Object> param) {
        // TODO Auto-generated method stub
        try {
            List<HashMap<String, Object>> list = (List<HashMap<String, Object>>) param.get("list");//得到导入excel文件里面的数据
            Integer company_id = (Integer) param.get("company_Id");
            for (HashMap<String, Object> result : list) {
                result.put("company_id", company_id);
                result.put("update_id", param.get("update_id"));
                result.put("update_name", param.get("update_name").toString());
                HashMap<String, Object> info = dealMapper.exlstsHeadInfo(result);//判断每条信息在数据库里是否存在
                if (info != null) {//如果数据存在则更新数据库
                    dealMapper.UpdateExcelAerMapping(result);
                } else {//如果数据不存在则将该条信息插入数据库
                    Double AMOUNT_CUR = Double.parseDouble(result.get("AMOUNT_CUR").toString());//明细表的含税金额
                    Double QUANTITY = Double.parseDouble(result.get("QUANTITY").toString());//明细表的数量
                    if (QUANTITY <= 0) {
                        QUANTITY = 1D;
                    }
                    Double TAX_AMOUNT = Double.parseDouble(result.get("TAX_AMOUNT").toString());//明细表的税额
                    Double PRICE_CUR = AMOUNT_CUR / QUANTITY;
                    PRICE_CUR = DoubleUtil.formatDigitDecimal(PRICE_CUR, 6);//计算单价，并保留六位小数到数据库
                    result.put("PRICE_CUR", PRICE_CUR);

                    Double AMOUNT_CUR_TOTAL = AMOUNT_CUR - TAX_AMOUNT;//获得不含税金额，用于insert 单据主表中
                    AMOUNT_CUR_TOTAL = DoubleUtil.formatDigitDecimal(AMOUNT_CUR_TOTAL, 2);
                    result.put("AMOUNT_CUR_TOTAL", AMOUNT_CUR_TOTAL);
                    dealMapper.ImportExcelAerMapping(result);
                    //dealMapper.ImportExcelAerDetailMapping(result);
                }
            }

//			dealMapper.ImportExcelAerMapping(param);//打印回写时，若本地数据库无指定票据的操作，默认为：插入此票据并将DOC_STATUS设置为1
//			dealMapper.UpdateExcelAerMapping(param);//打印回写时，若本地数据库有指定票据的操作，默认为：更新此票据，将DOC_STATUS设置为1
//			dealMapper.ImportExcelAerDetailMapping(param); //打印回写时，若本地数据库无指定明细项的操作，默认为：插入此明细项
//			dealMapper.UpdateExcelAerDetailMapping(param);//打印回写时，若本地数据库有指定明细项的操作，默认为：更新此明细项
            return 0;
        } catch (Exception ex) {
            ex.printStackTrace();
            logger.error(ex.getMessage());
            return -1;
        }
    }

    @Override
    public ArrayList<HashMap<String, String>> findDocNoByGoodsName(HashMap<String, Object> param) {
        // TODO Auto-generated method stub
        return dealMapper.findDocNoByGoodsName(param);
    }

    @Override
    public HashMap<String, Object> getHeadInfoByDocument(
            HashMap<String, Object> head) {
        // TODO Auto-generated method stub
        return dealMapper.getHeadInfoByDocument(head);
    }

    @Override
    public ArrayList<HashMap<String, Object>> getDetailInfoByDocument(
            HashMap<String, Object> head) {
        // TODO Auto-generated method stub
        return dealMapper.getDetailInfoByDocument(head);
    }

    @Override
    public List<HashMap<String, Object>> getPrintHeadInfo(HashMap<String, Object> map) {
        // TODO Auto-generated method stub
        return dealMapper.getPrintHeadInfo(map);
    }

    @Override
    public List<HashMap<String, Object>> getPrintDetailInfo(
            HashMap<String, Object> map) {
        // TODO Auto-generated method stub
        return dealMapper.getPrintDetailInfo(map);
    }

    @Override
    public ArrayList<HashMap<String, Object>> getBeforeDoc(HashMap<String, Object> param) {
        // TODO Auto-generated method stub
        return dealMapper.getBeforeDoc(param);
    }

    @Override
    public ArrayList<HashMap<String, Object>> getBrotherDoc(HashMap<String, Object> param) {
        // TODO Auto-generated method stub
        return dealMapper.getBrotherDoc(param);
    }

    @Override
    public ArrayList<HashMap<String, Object>> getdocStatusByBroDoc(HashMap<String, Object> param) {
        // TODO Auto-generated method stub
        return dealMapper.getdocStatusByBroDoc(param);
    }

    @Override
    public HashMap<String, Object> findinfoBydoc(HashMap<String, Object> map) {
        // TODO Auto-generated method stub

        return dealMapper.findinfoBydoc(map);
    }

    @Override
    public void insertInfo(HashMap<String, Object> map) {
        dealMapper.insertInfo(map);
    }

    @Override
    public void insertDetailInfo(List<HashMap<String, Object>> list) {
        dealMapper.insertDetailInfo(list);
    }

    @Override
    public HashMap<String, Object> getClientIp() {
        // TODO Auto-generated method stub
        return dealMapper.getClientIp();
    }

    @Override
    public void saveIpAddress(HashMap<String, Object> map) {
        dealMapper.saveIpAddress(map);
    }

    @Override
    public void delectClientIp(HashMap<String, Object> map) {
        dealMapper.delectClientIp(map);
    }

    @Override
    public void editNum(HashMap<String, Object> param) {
        dealMapper.editNum(param);
    }

    @Override
    public int checkDetailAmount(HashMap<String, Object> param) {
        try {
            ArrayList<HashMap<String, Object>> details = dealMapper.checkDetailAmount(param);
            StringBuffer docNO = new StringBuffer();
            HashMap<String, Object> docMap = new HashMap<String, Object>();
            if (!details.isEmpty()) {
                for (int i = 0; i < details.size(); i++) {
                    if ((Double.parseDouble(details.get(i).get("AMOUNT_CUR").toString()) <= 0)
                            && !(details.get(i).get("GOODS_NAME").toString().equals("折扣"))) {
                        String thisDoc = details.get(i).get("DOCUMENT_NO").toString();
                        if (!docMap.containsKey(thisDoc)) {
                            docMap.put(thisDoc, thisDoc);
                        }
                    }
                }
            }
            if (docMap.size() == 0) {
                return 0;
            }
            //将不符合条件的票据号拼成字符串，返回给前台
            String[] docList = docMap.values().toArray(new String[0]);//将哈希表的value取出放入String数组
            for (int j = 0; j < docList.length; j++) {
                if (j > 0) {
                    docNO.append(",");
                }
                docNO.append(docList[j].toString());
            }
            param.put("docNO", docNO);//????
            return 99;
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return -1;
        }
    }

    @Override
    public ArrayList<HashMap<String, Object>> getDealScanList(HashMap<String, Object> param) {
        int count = dealMapper.getDealScanListCount(param);
        if (count == 0) {
            return null;
        } else {
            param.put("pageCount", count);
            return dealMapper.getDealScanList(param);
        }
    }

    @Override
    public ArrayList<HashMap<String, Object>> getExpressType(
            HashMap<String, Object> param) {
        try {
            return dealMapper.getExpressType(param);
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return null;
        }
    }

    @Override
    public ArrayList<HashMap<String, Object>> getExpressTypeByname(
            HashMap<String, Object> param) {
        try {
            return dealMapper.getExpressTypeByname(param);
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return null;
        }
    }

    @Override
    public ArrayList<HashMap<String, Object>> getExpressType1(
            HashMap<String, Object> param) {
        try {
            return dealMapper.getExpressType1(param);
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return null;
        }
    }

    @Override
    public ArrayList<HashMap<String, Object>> getExpressType2() {
        try {
            return dealMapper.getExpressType2();
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return null;
        }
    }

    @Override
    public int saveExpressNo(HashMap<String, Object> param) {
        try {
            dealMapper.saveExpressNo(param);
            return 0;
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return -1;
        }
    }

    @Override
    public List<HashMap<String, Object>> getIpAddress(String ipAddress) {
        // TODO Auto-generated method stub
        return dealMapper.getIpAddress(ipAddress);
    }

    @Override
    public Integer getIPCount(HashMap<String, Object> param) {
        // TODO Auto-generated method stub
        return dealMapper.getIPCount(param);
    }

    @Override
    public ArrayList<HashMap<String, Object>> getExpressNO(
            HashMap<String, Object> param) {
        try {
            return dealMapper.getExpressNO(param);
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return null;
        }
    }

    /**
     * 获取快递公司code接口实现
     */
    @Override
    public String getExpressCode(HashMap<String, Object> param) {
        try {
            return dealMapper.getExpressCode(param);
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            return null;
        }
    }

    // 获取快递单扫描新增快递单号的单据信息
    @Override
    public HashMap<String, Object> getDataForExpress(
            HashMap<String, Object> param) {
        // TODO Auto-generated method stub
        return dealMapper.getDataForExpress(param);
    }

    // 检查当前公司是否启用快递100功能
    @Override
    public int getExpressStatus(String companyId) {
        // TODO Auto-generated method stub
        return dealMapper.getExpressStatus(companyId);
    }

    // 获取发票代码和号码
    @Override
    public HashMap<String, Object> getInvoiceNCode(
            HashMap<String, Object> param) {
        return dealMapper.getInvoiceNCode(param);
    }

    // 获取快递单号
    @Override
    public ArrayList<HashMap<String, Object>> getDealScanExpressNo(
            HashMap<String, Object> param) {
        // TODO Auto-generated method stub
        return dealMapper.getDealScanExpressNo(param);
    }

    /**
     *获取快递单打印信息接口实现
     */
    /*@Override
    public List<ExpressPrint> getExpressPrintList(HashMap<String,Object> inputparam){
		int count = 0;
		try{
			count = dealMapper.getExpressPrintListCount(inputparam);
		}
		catch(Exception e){
			logger.error(e.getMessage());
			return null;
		}
	    List<ExpressPrint> results = new ArrayList<ExpressPrint>();
		if(count == 0){
			return null;
		}
		else{
			ArrayList<HashMap<String,Object>> expressPrints;
			inputparam.put("pageCount", count);
			try{
				expressPrints = dealMapper.getExpressPrintList(inputparam);
			}
			catch(Exception e){
				logger.error(e.getMessage());
				return null;
			}
			for(int i=0; i<expressPrints.size(); i++){
	    		
				HashMap<String, Object> param = expressPrints.get(i);
	     		
				ExpressPrint expressPrint = new ExpressPrint();
				expressPrint.setId(Integer.parseInt(param.get("id").toString()));
				expressPrint.setExpress(param.get("express").toString());
				expressPrint.setDocument_no(param.get("document_no").toString());
				expressPrint.setDocument_date(param.get("document_date").toString());
				expressPrint.setCustomer(param.get("customer").toString());
				expressPrint.setReceiver(param.get("receiver").toString());
				expressPrint.setAmount(param.get("amount").toString());
				expressPrint.setTax_amount(param.get("tax_amount").toString());
				expressPrint.setStatus(param.get("status").toString());
				expressPrint.setRemark(param.get("remark").toString());
				results.add(expressPrint);
			}
		}
	    return results;
	}*/


}
